using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class bulletAction : MonoBehaviour
{
    // 由哪个玩家发出的
    public int PlayerId;
    public Color[] bulletColor;
    void Start()
    {
        GetComponent<SpriteRenderer>().color=bulletColor[PlayerId];
    }
    void OnTriggerEnter2D(Collider2D other)
    {
        CustomStayFunction(other);
        
        
    }

    void OnTriggerStay2D(Collider2D other)
    {
        CustomStayFunction(other);
        
    }

    void CustomStayFunction(Collider2D other)
    {
        if(other.tag=="Coin")
                return;
        try
        {
            if(other.gameObject.GetComponent<soldier>().PlayerId==PlayerId)
                return;
            
            if(other.tag=="Player"&&PlayerId!=GameObject.Find("UdpServer").GetComponent<WebSocketDemo>().PlayerId)
                GameObject.Find("UdpServer").GetComponent<WebSocketDemo>().PlayerHealth[other.gameObject.GetComponent<PlayerMove>().PlayerId]-=1;
            if(other.tag=="trooper")
                other.gameObject.GetComponent<soldier>().Health-=1;
            
        }
        catch
        {

        }
        if(other.gameObject.name=="爆金币")
        {
            other.gameObject.GetComponent<createGold>().hitAnimation=true;
        }
        Destroy(gameObject);

    }

}
